from selenium import webdriver
import time

# email = input('请输入你要发送的邮箱')
# message = input('请输入你要发送的信息')
test = webdriver.Chrome('E:\浏览器插件（chrome）/chromedriver.exe')
test.get('https://mail.163.com/')
# xpath找到iframe
iframe = test.find_element_by_xpath('//div[@id="loginDiv"]/iframe[@scrolling = "no"]')
# 切换到iframe下
test.switch_to.frame(iframe)
# 输入邮箱号
test.find_element_by_xpath('//input[@name="email"]').send_keys('FA485803186')
# 输入密码
test.find_element_by_xpath('//div[@class="u-input box"]//input[@name="password"]').send_keys('F485803186')
# 点击登录按钮
test.find_element_by_xpath('.//*[@id="dologin"]').click()
time.sleep(3)
# 点击写信
test.find_element_by_xpath('//*[@id="_mail_component_132_132"]').click()
# 输入发送到哪个email邮箱
test.find_element_by_xpath('//*/input[@class="nui-editableAddr-ipt"]').send_keys('dong4716138@163.com')
# 输入发送到主题
test.find_element_by_xpath('//div[@class="bz0"]/div[@aria-label="邮件主题输入框，请输入邮件主题"]/input').send_keys('代码输入完成')
# xpath找到iframe
iframe = test.find_element_by_xpath('//div[@class="APP-editor-edtr"]/iframe[@class="APP-editor-iframe"]')
# 切换到iframe下
test.switch_to.frame(iframe)
# 输入内容发送
test.find_element_by_xpath('//body[@class="nui-scroll"]/p').send_keys('完成代码进行程序')
# 退出iframe的切换
test.switch_to.default_content()
# 点击发送
test.find_element_by_xpath('//footer[@class="jp0"]/div[@role="button"][1]/span[@class="nui-btn-text"]').click()
